- /* slostrm.cpp by K.Tsuru */
- // function ID = 263 DARDIX
- /***************
- SLong class
- output stream since version 2.30
- ****************/
- #ifndef SN_H
- #include "sn.h"
- #endif
- /*
- It returns n-th digit by a character. n = 0 for first position
- For continuously picking out a static array buff[] is used.
- int SLong::CharNthFig(long n) const;
- in "slmput.cpp".
- */
-
- /*
- main body
- */
- long SLong::figUnit = 10;
- int SLong::perLine = 0;
- int SLong::lineFormat = SLong::CRLF;
- int SLong::delmt = ' ';
- long SLong::ioCount = 0; // the number of input or output characters
- // static void SetFormat(long fU, long pL = 0, int lF = CRLF, int dm = ' '); in slong.h
- // enum { NO_CR = 0, CRLF = 1, CONTINUE = 2, END_CR =4 };
- void SLong::SetFormat(long fU, long pL, int lF, int dm){
- figUnit = fU; perLine = pL; lineFormat = lF; delmt = dm;
- }
- void SLong::DefaultFormat(){ // It restores the default values.
- figUnit = 10; perLine = 0; lineFormat = CRLF; delmt = ' ';
- }
- ostream& operator<<(ostream& os, const SLong& sl)
- {
- // sl.SignCheck(204); // sign == UNDECIDED ?
- SLong temp(sl);
- sl.ioCount = 0;
-
- if(!sl.figUnit){ sl.figUnit = LONG_MAX; sl.delmt = 0; }
- long f = temp.DFigures();
- long numCount = f; //counter for output digits
- int uCount = 0; //counter for 'fig' figures
- long lunit = sl.perLine ? sl.perLine : (displayWidth+1)/(sl.figUnit+1);//units per line
-
- if(temp.Sign(204) == 0){ os.put('0'); sl.ioCount++; goto Ret; }
- if(!lunit) lunit = 1;
- //output negative sign
- if( temp.Sign(204) == -1 ) { os.put('-'); sl.ioCount++; }
-
- //integral part
- temp.CharNthFig(-1L);
- while(1){
- os.put( temp.CharNthFig(numCount -1) ); sl.ioCount++;
- numCount--;
- if(!numCount) break;
- if( !(numCount % sl.figUnit) ) { //output one unit
- uCount++;
- if(!(uCount % lunit)){ //reach the end of line
- if(sl.delmt != ' ') {
- os.put(sl.delmt); sl.ioCount++;
- }
- if(sl.lineFormat & sl.CONTINUE){ os.put('\\'); sl.ioCount++; }
- if(sl.lineFormat & sl.CRLF) { os << endl; sl.ioCount++; }
- if(sl.lineFormat == sl.NO_CR) { os.put(sl.delmt); sl.ioCount++; }
- } else {
- os.put(sl.delmt); sl.ioCount++;
- }
- }
- }
- Ret:
- if(sl.lineFormat & sl.END_CR){ os << endl; sl.ioCount++; }
- return os;
- }
slostrm.cpp : last modifiled at 2017/07/17 15:28:16(2,268 bytes)
created at 2017/10/07 10:26:49
The creation time of this html file is 2017/11/09 14:52:03 (Thu Nov 09 14:52:03 2017).